<?php
include_once dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))).'/ns_core/m_load.class.php';
\ns_core\m_load::load("ns_core.m_public");
\ns_core\m_load::load_np("np_string.php");
define('DEFAULT_SOURCE_ID','jycm');
if(!empty($_POST))
{
    if( empty($_POST['host']) || !preg_match('/^http.+/',$_POST['host']))
    {
        die('下游接收地址有误');
    }

    if( empty($_POST['content']) || !m_public::is_xml($_POST['content']) )
    {
        die('xml内容有误');
    }

    if( empty($_POST['cp_id'])  )
    {
        die('cp_id为空');
    }

    if( empty($_POST['sp_id'])  )
    {
        die('sp_id为空');
    }



    $url = $_POST['host'];
    //请求import.php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);


    //组装交信xml
    /*    $xml ='<?xml version="1.0" encoding="UTF-8"?>';*/
//    $xml.='<xmlpost>';
//    $xml.= '<time>'.date("Ymdhis").micortime().'</time>>';
//    $xml.= '<msgid>'.np_guid_rand().'</msgid>>';
//    $xml.='<cp_id>'.DEFAULT_SOURCE_ID.'</cp_id>';
//    $xml.='<url>'..'</url>';
//    $xml.='</xmlpost>';

    $post_data = array(
        'cmspost'=>$_POST['content'],
        'msgid'=>$_POST['msgid'],
        'cp_id'=>$_POST['cp_id'],
        'sp_id'=>$_POST['sp_id']
    );

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $data = curl_exec($ch);
    curl_close($ch);
    var_dump($data);
}
else
{
//拼接请求url
$uri = explode('/',$_SERVER['REQUEST_URI']);
array_pop($uri);
array_pop($uri);
$uri = implode('/',$uri);  
$url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$uri.'/import.php';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>注入</title>
        <style>
            input{
                width:50%;
            }
        </style>
    </head>
    <body>
    <form method="post" action="./test_adi.php">
        下游接收http地址：<br>
        <input type="text"  name="host" value="<?php echo $url?>" "><br>

        上游标识cp_id: <br>
        <input name="cp_id" type='text' value='jycm'><br/><br>
        下游标识sp_id: <br>
        <input name="sp_id" type='text' value='jscn_bkzx'><br/><br>

        注入xml文件内容： <br>
        <textarea name="content" cols=180 rows=20>
<ADI>
<Metadata>
<AMS Verb="" Asset_Class="packages" Asset_ID="jycmPAPT01829320" Asset_Name="女排世锦赛：非洲“姐妹”联手创历史" Provider_ID="jycm" Provider="jycm" Creation_Date="2018-11-14" Description="两支非洲球队喀麦隆和肯尼亚双双奏凯，完成了在世锦赛的历史性突破。" Version_Major="1" Version_Minor="0" Product="MOD"/>
<App_Data Value="CableLabsVOD 1.1" Name="Metadata_Spec_Version" App="MOD"/>
</Metadata>
<Asset>
<Metadata>
<AMS Verb="" Asset_Class="title" Asset_ID="jycmPA0000182932" Asset_Name="女排世锦赛：非洲“姐妹”联手创历史" Provider_ID="jycm" Provider="jycm" Creation_Date="2018-11-14" Description="两支非洲球队喀麦隆和肯尼亚双双奏凯，完成了在世锦赛的历史性突破。" Version_Major="1" Version_Minor="0" Product="MOD"/>
<App_Data Value="program" Name="Show_Type" App="MOD"/>
<App_Data Value="0" Name="Issue_Number" App="MOD"/>
<App_Data Value="jycmPA0000182932" Name="Original_Asset_ID" App="MOD"/>
<App_Data Value="1" Name="Original_System_ID" App="MOD"/>
<App_Data Value="1" Name="License_Type" App="MOD"/>
<App_Data Value="Culture" Name="Genre" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Proper_Title" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Parallel_Proper_Title" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Subordinate_Title" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Alternative_ Title" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Title_Description" App="MOD"/>
<App_Data Value="11" Name="Version_Description" App="MOD"/>
<App_Data Value="" Name="Key_Words" App="MOD"/>
<App_Data Value="两支非洲球队喀麦隆和肯尼亚双双奏凯，完成了在世锦赛的历史性突破。" Name="Description" App="MOD"/>
<App_Data Value="" Name="Impressive_Dialogue" App="MOD"/>
<App_Data Value="" Name="Impressive_Plot" App="MOD"/>
<App_Data Value="" Name="Hot_Comments" App="MOD"/>
<App_Data Value="" Name="Sentence_Review" App="MOD"/>
<App_Data Value="" Name="Behind_Scenes" App="MOD"/>
<App_Data Value="6.8" Name="IMDB_Rating" App="MOD"/>
<App_Data Value="G" Name="MPAA_Rating" App="MOD"/>
<App_Data Value="Y" Name="Season_Premiere" App="MOD"/>
<App_Data Value="N" Name="Season_Finale" App="MOD"/>
<App_Data Value="00:00:00" Name="Preview_Period" App="MOD"/>
<App_Data Value="5" Name="Asset_Recommend_Class" App="MOD"/>
<App_Data Value="0" Name="Chapter" App="MOD"/>
<App_Data Value="2018" Name="Year" App="MOD"/>
<App_Data Value="0.0" Name="Suggested_Price" App="MOD"/>
<App_Data Value="Adult" Name="Audience" App="MOD"/>
<App_Data Value="2056-01-01 20:00:00" Name="Subscriber_View_Limit" App="MOD"/>
<App_Data Value="" Name="Region" App="MOD"/>
</Metadata>
<Asset>
<Metadata>
<AMS Verb="" Asset_Class="language" Asset_ID="jycmLAPT01829320" Asset_Name="女排世锦赛：非洲“姐妹”联手创历史" Provider_ID="jycm" Provider="jycm" Creation_Date="2018-11-14" Description="女排世锦赛：非洲“姐妹”联手创历史" Version_Major="1" Version_Minor="0" Product="MOD"/>
<App_Data Value="zh" Name="Type" App="MOD"/>
<App_Data Value="CH" Name="Description" App="MOD"/>
<App_Data Value="zh_CN" Name="Tag" App="MOD"/>
<App_Data Value="99" Name="Regin" App="MOD"/>
<App_Data Value="南京一中" Name="Producers" App="MOD"/>
<App_Data Value="" Name="Actors" App="MOD"/>
<App_Data Value="" Name="Director" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Title" App="MOD"/>
<App_Data Value="女排世锦赛：非洲“姐妹”联手创历史" Name="Title_Brief" App="MOD"/>
</Metadata>
</Asset>
<Asset>
<Metadata>
<AMS Verb="" Asset_Class="movie" Asset_ID="jycmMV0001435786" Asset_Name="女排世锦赛：非洲“姐妹”联手创历史第1集" Provider_ID="jycm" Provider="jycm" Creation_Date="2018-11-14" Description="女排世锦赛：非洲“姐妹”联手创历史第1集" Version_Major="1" Version_Minor="0" Product="MOD"/>
<App_Data Value="jycmMV0001435786" Name="Original_Asset_ID" App="MOD"/>
<App_Data Value="1" Name="Original_System_ID" App="MOD"/>
<App_Data Value="2" Name="Service_Type" App="MOD"/>
<App_Data Value="1" Name="Screen_Format" App="MOD"/>
<App_Data Value="Y" Name="HD_Content" App="MOD"/>
<App_Data Value="" Name="3D_Content" App="MOD"/>
<App_Data Value="2" Name="Video_Bit_Rate" App="MOD"/>
<App_Data Value="1080" Name="Frame_Height" App="MOD"/>
<App_Data Value="1920" Name="Frame_Width" App="MOD"/>
<App_Data Value="N" Name="Encryption" App="MOD"/>
<App_Data Value="02:35:15" Name="Run_Time" App="MOD"/>
<App_Data Value="7002000" Name="Audio_Bit_Rate" App="MOD"/>
<App_Data Value="9c9d0b4fb0ebb90b9f0d030df4eefe08" Name="Content_Check_Sum" App="MOD"/>
<App_Data Value="1" Name="Security_Classification" App="MOD"/>
<App_Data Value="" Name="Remarks" App="MOD"/>
<App_Data Value="58581928" Name="Content_File_Size" App="MOD"/>
<App_Data Value="1" Name="Encryption_Reason" App="MOD"/>
<App_Data Value="" Name="Audio_Language" App="MOD"/>
<App_Data Value="zh_CN" Name="Subtitle_Language" App="MOD"/>
<App_Data Value="" Name="Audio_Bit_Depth" App="MOD"/>
<App_Data Value="" Name="Audio_Sampling_Frequency" App="MOD"/>
<App_Data Value="0" Name="Audio_Type" App="MOD"/>
<App_Data Value="" Name="Audio_Coding_Format" App="MOD"/>
<App_Data Value="" Name="Video_Sampling_Type" App="MOD"/>
<App_Data Value="" Name="Video_Coding_Format" App="MOD"/>
<App_Data Value="PAL" Name="System" App="MOD"/>
<App_Data Value="" Name="Aspect_Ratio" App="MOD"/>
<App_Data Value="5" Name="Video_Quality" App="MOD"/>
<App_Data Value="1" Name="Audio_Channel_Format" App="MOD"/>
<App_Data Value="1" Name="Color" App="MOD"/>
<App_Data Value="" Name="Starting_Point" App="MOD"/>
<App_Data Value="HD" Name="MediaMode" App="MOD"/>
<App_Data Value="4K" Name="FileType" App="MOD"/>
</Metadata>
<Content Value="ftp://ftpadmin:123456@118.25.209.242/kfc.ts"/>
</Asset>
</Asset>
</ADI>
        </textarea><br/><br/>

        消息id(不写自动生成): <br>
        <input name="msgid" type='text' value=''><br/><br>
        <input type="submit" value="提交"/>
    </form>
    </body>
    </html>

    <?php
}
?>
